package cn.yotta.user.web.autoconfiguration.token;

import cn.yotta.user.web.autoconfiguration.context.header.CookieContext;
import lombok.Setter;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wyaoyao
 * @date 2023/3/11 11:10
 */
public class CookieLoginTokenObtainStrategy implements LoginTokenObtainStrategy {

    @Setter
    private String cookieName;

    public CookieLoginTokenObtainStrategy(String cookieName) {
        this.cookieName = cookieName;
    }

    @Override
    public String getToken(HttpServletRequest httpServletRequest) {
        return getTokenFromCookie();
    }

    protected String getTokenFromCookie() {
        return CookieContext.getCookie(cookieName);
    }
}
